import 'package:flutter/material.dart';
import 'package:flutter_sample/tab/bean/article_bean.dart';

/// 主页列表条目ui
class UIArticleItem extends StatelessWidget {
  final ArticleBean data;
  final double widgetHeight = 80;

  const UIArticleItem(this.data, {Key? key}) : super(key: key);

  Widget _buildLeftWidget() {
    return Column(crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
      Text(data.title, maxLines: 2, style: const TextStyle(fontSize: 16)),
      Row(
        children: [
          Text(
            "${data.price}毛/阅读",
            maxLines: 1,
            style: const TextStyle(
              fontSize: 13,
              color: Colors.red,
            ),
          ),
          const SizedBox(width: 10),
          Text(
            "已发放${data.payAmount}元",
            maxLines: 1,
            style: const TextStyle(
              fontSize: 13,
              color: Colors.red,
            ),
          ),
        ],
      )
    ]);
  }

  Widget _buildRightWidget(double widgetHeight) {
    double widgetWidth = 4.5 * widgetHeight / 3;
    return Container(
      width: widgetWidth,
      height: widgetHeight,
      padding: const EdgeInsets.only(left: 10.0),
      child: ClipRRect(borderRadius: const BorderRadius.all(Radius.circular(4)), child: Image.network(
        data.imageUrl,
        fit: BoxFit.cover,
      ),),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        Expanded(child: SizedBox(height: widgetHeight, child: _buildLeftWidget(),)),
        _buildRightWidget(widgetHeight),
      ],
    );
  }
}
